package com.tsubaki.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tsubaki.entity.Course;
import com.tsubaki.entity.School;
import com.tsubaki.entity.User;
import com.tsubaki.mapper.SchoolMapper;
import com.tsubaki.service.SchoolService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author tsubaki
 * @since 2022-01-17
 */
@Service
public class SchoolServiceImpl extends ServiceImpl<SchoolMapper, School> implements SchoolService {

    @Autowired
    private SchoolMapper schoolMapper;

    @Override
    public Map<String, Object> getAll(Integer pageNum, Integer pageSize) {
        int first = pageNum == null ? 1 : pageNum;
        int second = pageSize == null ? 5 : pageSize;
        PageHelper.startPage(first, second);

        List<School> schools = schoolMapper.getAll();

        PageInfo pageInfo = new PageInfo(schools);
        Map<String, Object> map = new HashMap<>();
        map.put("total", pageInfo.getTotal());
        List<Map<String, Object>> list = new ArrayList<>();
        for (School school : schools) {
            Map<String, Object> map1 = new HashMap<>();
            map1.put("school", school);
            list.add(map1);
        }
        map.put("list", list);
        return map;
    }

//    @Override
//    public Map<String, Object> getAllName() {
//        List<School> schools = schoolMapper.getAllName();
//        Map<String, Object> map = new HashMap<>();
//        map.put("total", schools.size());
//        List<Map<String, Object>> list = new ArrayList<>();
//        for (School school : schools) {
//            Map<String, Object> map1 = new HashMap<>();
//            map1.put("school", school);
//            list.add(map1);
//        }
//        map.put("list", list);
//        return map;
//    }
}
